package com.his.invdrug.controller;

import com.his.config.annotation.CurrentUser;
import com.his.invdrug.entity.DictInvpropOrgid;
import com.his.invdrug.service.DictInvpropOrgidService;
import com.his.invdrug.vo.DictInvpropOrgidVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存事务来源去向配置控制类
 * @Author tansonglin
 * @Date 2020/3/20
 */
@RestController
@RequestMapping(value="/api/dict_invprop_orgid")
public class DictInvpropOrgidController extends ResultBaseController {

    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictInvpropOrgidService dictInvpropOrgidService;

    /**
     *   通过事务ID查询该事务所有的来源去向配置
     * @param invporpID 出入库事务ID
     */
    @GetMapping(value="/query_by_invporpid.do")
    public ResultUtil queryByInvporpID(@CurrentUser DictEmployee dictEmployee,String invporpID){
        try{
            List<DictInvpropOrgid> dictInvpropOrgids=dictInvpropOrgidService.queryByInvporpID(dictEmployee,invporpID);
            return this.success("成功",dictInvpropOrgids);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     *插入配置信息
     */
    @PostMapping(value="/insert.do")
    public ResultUtil insertDictInvpropOrgid(@CurrentUser DictEmployee dictEmployee, @RequestBody DictInvpropOrgidVo dictInvpropOrgidVo){
        try{
            dictInvpropOrgidService.insert(dictEmployee,dictInvpropOrgidVo);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     *修改配置信息-判断过滤
     */
    @PostMapping(value="/update_by_Selective.do")
    public ResultUtil updateDictInvpropOrgid(@CurrentUser DictEmployee dictEmployee,@RequestBody DictInvpropOrgidVo dictInvpropOrgidVo){
        try{
            dictInvpropOrgidService.updateBySelective(dictInvpropOrgidVo);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     *删除配置信息
     */
    @GetMapping(value="/delete.do")
    public ResultUtil deleteDictInvpropOrgid(@CurrentUser DictEmployee dictEmployee,String id){
        try{
            dictInvpropOrgidService.deleteByKey(id);
            return this.success("成功",null);
        }catch(Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
